import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import api from './api/api.js'
import publicData from './js/public.js'

import ElementPlus from 'element-plus'
import elementIcon from "./js/svgicon";
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import './style/index.scss'
import utils from './js/utils.js'
import 'element-plus/theme-chalk/src/message.scss'
import 'element-plus/theme-chalk/src/message-box.scss'

// 页面标题对应router里自定义的title
router.beforeEach((to,from,next)=>{

   console.log(store.state.token)
   if(store.state.token || to.meta.notoken ){
    if(to.path=='/'){
       next('/yonghuliebiao')
     }else{
       next();
     }
   }else{
     next({path: '/login', query: {redirect: to.path}})
   }

})

const app = createApp(App)
app.config.globalProperties.$api = api;
app.config.globalProperties.$msgbox = ElMessageBox;
app.config.globalProperties.$public = publicData;
app.config.globalProperties.utils = utils;
app.use(store).use(router).use(elementIcon)
.use(ElementPlus, {
    locale: zhCn,
  })
.mount('#app')
